<?php
/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */
?>
<div class="row-fluid">
    <div class="span6">
        <?php
        $labelsData = array();
        if ($type == 'bar')
        {
            foreach ($stats['FieldOption'] as $opt)
            {
                $labelsData[$opt['title']] = $opt['count'];
            }
            echo $this->Jqplot->renderBar($labelsData, array('title' => $stats['Field']['title']));
        }
        else
        {
            if ($stats['Field']['type'] != 'checkbox')
            {
                $labelsData = array();
                foreach ($stats['FieldOption'] as $opt)
                    $labelsData[$opt['title']] = $opt['count'];

                $qSum = array_sum($labelsData);
                if (($notAnswered = $count - $qSum) > 0)
                    $labelsData[__('Not answered')] = $notAnswered;

                echo $this->Jqplot->renderPie($labelsData, array('title' => $stats['Field']['title']));
            }
            else
            {
                $selected = $unSelected = 0;
                foreach ($stats['values'] as $val)
                {
                    if ($val == '1')
                        $selected++;
                    else
                        $unSelected++;
                }

                $labelsData[__('Selected')] = $selected;
                $labelsData[__('Unselected')] = $unSelected;

                echo $this->Jqplot->renderPie($labelsData, array('title' => $stats['Field']['title']));
            }
        }
        ?>
    </div>
    <div class="span6">
        <div class="well">
            <?php echo $this->element('statistics/counts', array('stats' => $labelsData, 'count' => $count)); ?>
        </div>
    </div>
</div>